<template>
  <!-- 添加或修改发货单明细对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="删除标志" prop="delFlag">
                <el-input v-model="form.delFlag" placeholder="请输入删除标志"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" placeholder="请输入备注"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发货通知id" prop="tongzhiId">
                <el-input v-model="form.tongzhiId" placeholder="请输入发货通知id"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发货通知编号" prop="tongzhiNo">
                <el-input v-model="form.tongzhiNo" placeholder="请输入发货通知编号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="交货日期" prop="jiaohuoDate">
                <el-date-picker clearable
                                v-model="form.jiaohuoDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择交货日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购单号" prop="caigouNo">
                <el-input v-model="form.caigouNo" placeholder="请输入采购单号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供货单号" prop="gonghuoNo">
                <el-input v-model="form.gonghuoNo" placeholder="请输入供货单号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="订单id" prop="proId">
                <el-input v-model="form.proId" placeholder="请输入订单id"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="订单编号" prop="proNo">
                <el-input v-model="form.proNo" placeholder="请输入订单编号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="订单产品id" prop="saleId">
                <el-input v-model="form.saleId" placeholder="请输入订单产品id"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="产品名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入产品名称"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="产品型号" prop="models">
                <el-input v-model="form.models" placeholder="请输入产品型号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="产品明细" prop="mingxi">
                <el-input v-model="form.mingxi" placeholder="请输入产品明细"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="产品编号" prop="nos">
                <el-input v-model="form.nos" placeholder="请输入产品编号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单位" prop="danwei">
                <el-input v-model="form.danwei" placeholder="请输入单位"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="产品单价" prop="danjian">
                <el-input v-model="form.danjian" placeholder="请输入产品单价"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发货数量" prop="shuliang">
                <el-input v-model="form.shuliang" placeholder="请输入发货数量"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发货金额" prop="money">
                <el-input v-model="form.money" placeholder="请输入发货金额"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发货单id" prop="fahuoId">
                <el-input v-model="form.fahuoId" placeholder="请输入发货单id"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发货单号" prop="fahuoNo">
                <el-input v-model="form.fahuoNo" placeholder="请输入发货单号"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addAction, getById, updateAction} from '@/api/manage';
import moment from 'moment';

export default {
  name: "LvYifahuomingxiForm",
  data() {
    return {
      title: '',
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      url: {
        getById: '/lvYifahuomingxi/lvYifahuomingxi/',
        add: '/lvYifahuomingxi/lvYifahuomingxi/add',
        edit: '/lvYifahuomingxi/lvYifahuomingxi/edit',
      },
    };
  },
  created() {

  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        tongzhiId: null,
        tongzhiNo: null,
        jiaohuoDate: null,
        caigouNo: null,
        gonghuoNo: null,
        proId: null,
        proNo: null,
        prodName: null,
        saleId: null,
        name: null,
        models: null,
        mingxi: null,
        nos: null,
        danwei: null,
        danjian: null,
        shuliang: null,
        money: null,
        status: "0",
        fahuoId: null,
        fahuoNo: null
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加发货单明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改发货单明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.edit, this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.add, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },
  }
};
</script>
